package leetcode.code0970;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Solution20230502 {
	public List<Integer> powerfulIntegers(int x, int y, int bound) {
		Set<Integer> ans = new HashSet<>();
		for (int i = 0; i < 30 && (int) Math.pow(x, i) < bound; i++) {
			int X = (int) Math.pow(x, i);
			for (int j = 0; j < 30 && X + (int) Math.pow(y, j) <= bound; j++) {
				ans.add(X + (int) Math.pow(y, j));
			}
		}
		return new ArrayList<Integer>(ans);
	}
}
